Skip to content

Prevent page shift when navbar dropdown opens#2452

Merged
martinbonnin merged 1 commit into
graphql:sourcefrom
jeanlucaslima:fix/navbar-dropdown-scrollbar-shift
Jun 29, 2026
Merged

Prevent page shift when navbar dropdown opens#2452
martinbonnin merged 1 commit into
graphql:sourcefrom
jeanlucaslima:fix/navbar-dropdown-scrollbar-shift

Conversation

@jeanlucaslima

Copy link
Copy Markdown
Contributor

Problem

Opening a navbar dropdown (e.g. Community) locks page scroll by setting body { overflow: hidden } (src/components/navbar/navbar.tsx). On pages tall enough to show a scrollbar, this removes the ~15px viewport scrollbar. Because no space was reserved for it, the whole page — including the full-width navbar — shifts sideways by the scrollbar width as the menu opens and back when it closes.

Fix

Reserve the scrollbar gutter on html so the layout width stays constant whether or not the scrollbar is present:

html {
  scrollbar-gutter: stable;
}

This is consistent with the scrollbar-gutter: stable already used on .nextra-scrollbar, and also covers the mobile menu and any other scroll-lock.

Note: padding-right compensation (the usual scroll-lock trick) does not work here, because the navbar is full-viewport-width and isn't constrained by the body content box.

Verification

Measured the navbar's right edge while clicking the Community trigger:

scrollbar-gutter nav right edge (closed → open) shift
Before auto 1490 → 1505 15px
After stable 1490 → 1490 0px

The scroll-lock still works as before; it just no longer shifts the page.

🤖 Generated with Claude Code

Opening a navbar dropdown (e.g. Community) locks body scroll via
`overflow: hidden`, removing the viewport scrollbar and shifting the whole
page sideways by the scrollbar width on scrollable pages.

Reserve the scrollbar gutter with `scrollbar-gutter: stable` on `html` so
the layout width stays constant whether or not the scrollbar is present.
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@jeanlucaslima is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@martinbonnin martinbonnin merged commit 9b3fa6d into graphql:source Jun 29, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants